package Key_Value类型

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object sortByKey {
    /*
     作用：在一个(K,V)的RDD上调用，K必须实现Ordered接口，返回一个按照key进行排序的(K,V)的RDD
     */

    def main(args: Array[String]): Unit = {

        val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("")

        val sc = new SparkContext(config)

        val rdd = sc.parallelize(Array((3, "aa"), (6, "cc"), (2, "bb"), (1, "dd")))

        val res1: RDD[(Int, String)] = rdd.sortByKey(true)

        res1.collect().foreach(println)

        val res2: RDD[(Int, String)] = rdd.sortByKey(false)

        res2.collect().foreach(println)
    }

}
